Matches正则使用提取内容 | 您所在的位置:网站首页 › Matches正则使用提取内容 › Matches正则使用提取内容 |
用VS新建WinForm程序,窗体上是三个文本框和一个按钮。可以自己构造正则表达式,自己修改匹配内容 正则表达是要提取的部分为hewenqitext 代码如下: using System; using System.Text.RegularExpressions; using System.Windows.Forms; namespace HoverTreeBatch.HoverTree { public partial class RegexForm : Form { public RegexForm() { InitializeComponent(); textBox_regex.Text = @""; textBox_content.Text = @""; } private void button_ok_Click(object sender, EventArgs e) { Regex m_hvtRegImg = new Regex(textBox_regex.Text, RegexOptions.IgnoreCase); //搜索匹配的字符串 MatchCollection hewenqi_matches; try { hewenqi_matches = m_hvtRegImg.Matches(textBox_content.Text); // 取得匹配项列表 foreach (Match match in hewenqi_matches) { textBox_result.Text = textBox_result.Text + match.Groups["hewenqitext"].Value + "\r\n"; } } catch (Exception ex) { textBox_result.Text = ex.ToString(); } } } } /* */转载自:http://hovertree.com/h/bjaf/nxoqir0b.htm http://www.cnblogs.com/sosoft/p/kaifajishu.html |
CopyRight 2018-2019 实验室设备网 版权所有 |